<?php

class StatsController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */
    }

    public function indexAction() {
        // action body
    }

    public function cumulvisiteurAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "select idVisiteur, mois, count(*) as nbFiches,sum(montantValide) as total
            from ficheFrais
            where idEtat = 'RB'
            group by idVisiteur, mois
            order by idVisiteur";

        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
    }

    public function cumulfraisAction() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $query = "select idVisiteur, mois,
        sum(case idfraisforfait when 'ETP' then quantite*montant END) as ETP,
        sum(case idfraisforfait when 'KM' then quantite*montant END) as KM,
        sum(case idfraisforfait when 'NUI' then quantite*montant END) as NUI,
        sum(case idfraisforfait when 'REP' then quantite*montant END) as REP
        from lignefraisforfait join fraisforfait on lignefraisforfait.idfraisforfait = fraisforfait.id 
        group by idVisiteur, mois";

        $lesStats = $db->fetchAll($query);
        $this->view->lesStats = $lesStats;
    }

}

